<?php

include_once "/../config.php";

class BaseDatos {

	function BaseDatos() {
	}

	function connectClass() {
		global $strings,$oConn,$databaseType;
		$MYCONNECTDATA = MYSERVER.":".MYPORT;
		$oConn= mysql_connect($MYCONNECTDATA,MYLOGIN,MYPASSWORD);
		mysql_select_db(MYDATABASE,$oConn);		
	}

	function query($sql) {		
		global $oConn;
		$this->sql = $sql;
		$this->result = mysql_query($sql,$oConn);	
		return $this->result;
	}
	
	function fetch($result) {
		if (!$result) {
			exit;
		}
		$row=mysql_fetch_array($result);
		return $row;
	}

	function close() {
		global $oConn;
		mysql_free_result($this->result);
		mysql_close($oConn);
	}

	function insertbd($query, $opt = true){
		global $oConn, $row, $sql;
		$this->connectClass();
		$sql = $query;
		$result = $this->query($sql);			
		if ($result){
			if($opt){
				$sql = "select last_insert_id()";
				$result = $this->query($sql);
				list($last_id) = $this->fetch($result);
				mysql_close($oConn);
				return $last_id;
			}
			return true;
		}else{
			global $msg; 
			$msg = $sql;			
			echo mysql_error();
			return false;
		}
	}
	

	function updatebd($query){
		global $oConn, $row, $sql;
		$this->connectClass();
		$result = $this->query($query);
		mysql_close($oConn);
		return $result;
	}	

	function deletebd($query){
		global $oConn, $row, $sql;
		$this->connectClass();
		$sql = $query;
		$result = $this->query($sql);
		mysql_close($oConn);
		if ($result){
			return true;
		}else{
			global $msg; 
			$msg = $sql;			
			return false;
		}
	}

	function numRows($result) {
		global $oConn;
		$count = mysql_num_rows($result);
		return $count;
	}
}
?>